package sample.clients;

import org.dom4j.util.UserDataAttribute;
import org.hibernate.HibernateException;

import com.sun.org.apache.bcel.internal.generic.GETSTATIC;

import sample.dao.DAO;
import sample.entity.User;

public class CreateUser  extends DAO{
	
	public static void main(String[] args) {
		System.out.println("Creating user");
		
		CreateUser self=new CreateUser();
		try{
			self.create("sdf", "12346");
			DAO.close();
		}
		catch(Exception e){
			System.out.println(e.getMessage());
		}
	}
	
	public User create(String username,String password) throws Exception{
		try{
			begin();
			User user=new User();
			user.setName(username);
			user.setPassword(password);
			getSession().save(user);
			commit();
			return user;
		}
		catch(HibernateException e){
			throw new Exception("Couldn't create a user");
		}
	}
	
}
